using System;
using SmartMathLibrary;

namespace SmartMathLibrary.QuadPack
{
    /// <summary>
    /// Computation of oscillatory integrals.
    /// </summary>
    [Serializable]
    public static class DqawoClass
    {
        /// <summary>
        /// Computes a oscillatory integral.
        /// </summary>
        /// <param name="f">Function defining the integrand function f(x). the actual name for f needs to be declared external in the driver program.</param>
        /// <param name="a">The lower limit of integration.</param>
        /// <param name="b">The upper limit of integration.</param>
        /// <param name="omega">Parameter in the integrand weight function.</param>
        /// <param name="sincos">Indicates which of the weight functions is to be used: = 1 - w(x) = cos(omega*x); = 2 - w(x) = sin(omega*x).</param>
        /// <param name="epsabs">The absolute accuracy requested.</param>
        /// <param name="epsrel">The relative accuracy requested.</param>
        /// <param name="abserr">The estimate of the modulus of the absolute error, which should equal or exceed abs(i-result).</param>
        /// <param name="neval">Number of integrand evaluations.</param>
        /// <param name="ier">The requested errorcode.</param>
        /// <returns>The approximation of the oscillatory integral.</returns>
        public static double Dqawo(HardRealFunction f, double a, double b, double omega, int sincos, double epsabs,
                                   double epsrel, ref double abserr, ref int neval, ref int ier)
        {
            double[,] chebmo = new double[QuadPackConstants.MAXP1,QuadPackConstants.MAXP1];
            double[] res3a = new double[52];

            int momcom = 0;
            double result = DqfourClass.Dqfour(f, a, b, omega, sincos, epsabs, epsrel, 1, QuadPackConstants.MAXP1,
                                               ref abserr,
                                               ref neval, ref ier, ref momcom, chebmo);


            return result;
        }
    }
}